<template>
	<view class="main">
		<view class="about1">
			<view class="about" v-if="yqm == 2">
				<view class="title">
					请输入邀请码
				</view>
				<input type="text" class="input" placeholder="请输入邀请码" v-model="keyword" maxlength='10'>
				<view class="tijiao" @click="tijiao">
					提交
				</view>
			</view>
			<view class="box" v-if="yqm == 1">
				<view class="content">
					邀请详情：您已被用户名（{{yqmid}}）邀请绑定。
				</view>
			</view>
		</view>
		<MyPopup v-if="show" :content='content' @showshow='showshow'></MyPopup>
	</view>
</template>

<script>
	import {
		Earnings
	} from "@/request/api.js"
	import MyPopup from "@/components/Popup.vue"
	export default {
		data() {
			return {
				keyword: '',
				yqm: '',
				yqmid: '',
				is_blogger: '',
				show: false,
				content: '',
			};
		},
		onLoad(option) {
			this.yqm = option.yqm
			this.yqmid = option.yqmid
		},
		methods: {
			tijiao() {
				if (this.keyword.trim() == '') {
					uni.showToast({
						title: '请填写邀请码',
						icon: 'none',
						duration: 2000
					})
				} else {
					this.code()
				}
			},
			showshow(e) {
				this.show = e
				uni.navigateBack({
					delta: 1
				})
			},
			async code() {
				let password = this.keyword.toString()
				let res = await Earnings.Code(password)
				if (res.error_code == 'API_USER_INVITE_002') {
					uni.showToast({
						title: '邀请码为必填项',
						icon: 'none',
						duration: 2000,
					})
				} else if (res.error_code == 'API_USER_INVITE_003') {
					uni.showToast({
						title: '博主不存在',
						icon: 'none',
						duration: 2000
					})
				} else if (res.error_code == 'API_USER_INVITE_004') {
					uni.showToast({
						title: '此邀请码暂时无法被绑定',
						icon: 'none',
						duration: 2000
					})
				} else if (res.error_code == 'API_USER_INVITE_005') {
					uni.showToast({
						title: '不可以填写自己的邀请码',
						icon: 'none',
						duration: 2000,
					})

				} else if (res.status_code == 200) {
					this.show = true
					this.content = '邀请码绑定成功'
				} else if (res.status_code == 422) {
					uni.showToast({
						title: '邀请码无效',
						icon: 'none',
						duration: 2000
					})
				}
			}
		},
		components: {
			MyPopup
		}
	}
</script>

<style lang="less" scoped>
	@import url("./Invite.less");
</style>